var express = require("express"),
	article = require("../../models/adminSite/article"),
	article = new article(),
	router = express.Router(),
	hotArticle = "",
	hot = function (req , res , next){
		article.getArticle({conditions : {Popular : 1}} , function(error , data){
			if(error){
				return res.end("<h2>操作失败</h3>");
			};
			(hotArticle = data) && next();
		});
	};
router.post("/search" , hot , function(req , res){
	var keyword = req.body.keyword,
		error = "";
	article.getArticle({conditions : {title : RegExp(keyword , "i")}} , function(error , article){
		if(error){
			error = "查找失败";
		};
		if(article.length <= 0 && !error){
			error = "没有搜索到您要的内容！可以换个关键词试试哦";
		};
		res.render("webSite/search" , {
			error : error,
			article : article,
			keyword : keyword,
			hotArticle : hotArticle
		});
	});
})
module.exports = router;
